#ifndef __1Wire_H__
#define __1Wire_H__

#include "common.h"

typedef void* POneWireBusCtx;
typedef uint64_t OneWireAddr;

// ---------------------------------------------------------------------------
// method declarations
// ---------------------------------------------------------------------------
uint8_t OWScanBusForDevices(POneWireBusCtx pBusCtx, OneWireAddr ROMs[], uint8_t maxSize);

uint8_t OWReadByte(POneWireBusCtx pBusCtx);
void    OWWriteByte(POneWireBusCtx pBusCtx, uint8_t byte_value);

#define OWInitIO   OWPortal_initIO
#define OWReset    OWPortal_reset
#define OWWriteBit OWPortal_writeBit
#define OWReadBit  OWPortal_readBit

// ---------------------------------------------------------------------------
// portal declarations per bsp
// ---------------------------------------------------------------------------
// initialize the IO configurations to the 1wire bus
void    OWPortal_initIO(POneWireBusCtx pBusCtx);

// Reset the 1-Wire bus and return the presence of any device
// Return TRUE  : device present
//        FALSE : no device present
BOOL    OWPortal_reset(POneWireBusCtx pBusCtx);

// Send 1 bit of data to teh 1-Wire bus
void    OWPortal_writeBit(POneWireBusCtx pBusCtx, uint8_t bit_value);

// Read 1 bit of data from the 1-Wire bus 
// Return 1 : bit read is 1
//        0 : bit read is 0
uint8_t OWPortal_readBit(POneWireBusCtx pBusCtx);

#ifndef BIT_PORTAL
extern void    OWPortal_dqH(POneWireBusCtx pBusCtx);
extern void    OWPortal_dqL(POneWireBusCtx pBusCtx);
extern uint8_t OWPortal_dqV(POneWireBusCtx pBusCtx);
#endif // BIT_PORTAL

// ---------------------------------------------------------------------------
// portal declarations per bsp
// ---------------------------------------------------------------------------

#endif  // __1Wire_H__


/*
// ---------------------------------------------------------------------------
// an sample at IO layer portal
// ---------------------------------------------------------------------------
void OWPortal_initIO(POneWireBusCtx pBusCtx)
{
 	GPIO_InitTypeDef GPIO_InitStructure;
 
 	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_1;
 	GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_OD;
 	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	OWReset(pBusCtx);
}

void OWPortal_dqH(POneWireBusCtx pBusCtx)
{
	GPIO_SetBits(GPIOA, GPIO_Pin_1);
}

void OWPortal_dqL(POneWireBusCtx pBusCtx)
{
	GPIO_ResetBits(GPIOA, GPIO_Pin_1);
}

uint8_t OWPortal_dqV(POneWireBusCtx pBusCtx)
{
	return GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1);
}
*/
